// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import './assets/font/iconfont.css'
import ele from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'

Vue.config.productionTip = false
Vue.use(ele)
Vue.use(mavonEditor)
/* eslint-disable no-new */

import axios from 'axios'
// axios.defaults.baseURL = "https://localhost:8088/"
axios.defaults.baseURL = "https://enwayouli.top:8088/"
Vue.prototype.axios = axios
Vue.prototype.$axios = axios

//
import LetItSnow from 'vue-let-it-snow';
Vue.use(LetItSnow);
//

new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})


  router.beforeEach((to,from,next) => {
  if (!to.path.startsWith('/editor')&&!to.path.startsWith('/mine')){
    next()
  } else {
    let admin = JSON.parse(window.localStorage.getItem("access-admin"))
    console.log(admin)
    if (admin == null){
      next({path: '/login'})
    } else {
      //校验token合法性
      axios({
        url: 'http://localhost:8080/checkToken',
        method: 'get',
        headers:{
          token: admin.token
        }
      }).then(res => {
        if (!res.data){
          console.log("校验失败")
          next({path: '/error'})
        }
      })
      next()
    }
  }
})

